using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace net.notdot.Attercop.Client
{
    public partial class PMWindow : Form
    {
        public ClientInstance ClientInstance;
        public Peer Peer;

        private MessageAddressing target;

        public PMWindow(ClientInstance c, Peer p)
        {
            this.ClientInstance = c;
            this.Peer = p;

            this.target = new MessageAddressing(c.LocalPeer.Address, p.Address);

            InitializeComponent();

            this.Text = string.Format("Private conversation with \"{0}\"", this.Peer.Nick);
        }

        private void txtChatEntry_KeyUp(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Enter:
                    CommandParser.Command cmd = CommandParser.Parse(txtChatEntry.Text);
                    switch (cmd.Type)
                    {
                        case CommandParser.CommandType.Invalid:
                            AddLine(string.Format("*** Command not recognised"));
                            break;
                        case CommandParser.CommandType.ChatMessage:
                            ClientInstance.SendMessage(new ChatMessage(target, cmd.Parameters[0]));
                            AddLine(string.Format(ServerWindow.ChatMessageFormat, ClientInstance.LocalPeer.Nick, cmd.Parameters[0]));
                            break;
                        case CommandParser.CommandType.Emote:
                            ClientInstance.SendMessage(new ChatMessage(target, cmd.Parameters[0], true));
                            AddLine(string.Format(ServerWindow.EmoteMessageFormat, ClientInstance.LocalPeer.Nick, cmd.Parameters[0]));
                            break;
                    }

                    txtChatEntry.Text = "";
                    break;
            }
        }
        
        public void AddLine(string s)
        {
            txtChatbox.Text += s + Environment.NewLine;
        }
    }
}